package com.guigu.servlet;

import com.google.gson.Gson;
import com.guigu.dao.BookDao;
import com.guigu.mapper.BookMapper;
import com.guigu.util.BookMapperFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/QueryAll.do")
public class QueryAllServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        String press = req.getParameter("press");
        String date = req.getParameter("date");
        Gson gson = new Gson();
        BookMapperFactory bmf = new BookMapperFactory();
        BookMapper bm =bmf.getMapper();
        String json = gson.toJson(bm.queryAll());
        bmf.closeSession();
        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().print(json);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doGet(req, resp);
    }
}
